<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        div{
            width: 600px;
            height: 400px;
            margin: 0 auto;
            border: 10px solid seagreen;
            position: relative;
            overflow: hidden;  /*超出部分隐藏*/
        }
        p{
            width: 60px;
            height: 100%;
            background: hotpink;
            position: absolute;
        }
    </style>
</head>
<body>
    <div id="box">
    </div>
    <script>
        

        setInterval(function(){
            var l = 500  /*柱子一开始出现的位置*/
            var zhuzi = document.createElement('p')  /*创建柱子*/
            zhuzi.style.left = l + 'px'  /*柱子的位置*/
            box.appendChild(zhuzi)  /*把柱子放在盒子里面*/
            setInterval(function () {
                l -= 3
                zhuzi.style.left = l + 'px'
            }, 30)
        }, 2000)  /*每隔两秒钟创建一个柱子*/
    </script>
</body>
</html>